package com.adv.ems.model.vo;

import com.adv.ems.db.entity.BuildingInfoDO;
import com.adv.ems.db.entity.DepartmentInfoDO;
import com.adv.ems.utils.EmsUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;
import java.util.ArrayList;
import java.util.List;

@Data
public class BaseDepartmentVO {
    private List<Info> list;

    public BaseDepartmentVO() {
        this.list = new ArrayList<Info>();
    }

    @EqualsAndHashCode(callSuper = true)
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Info extends DepartmentInfoDO {
        private String buildingName;

        public Info(DepartmentInfoDO department, BuildingInfoDO building, String acceptLanguage) {
            BeanUtils.copyProperties(department, this);
            if (building != null) {
                this.setBuildingName(EmsUtil.getNameInfo(building.getNameInfo(), acceptLanguage).getShortName());
            }
        }
    }
}
